﻿fastCSharp.Copy(fastCSharp.MathJax=fastCSharp.MathJax||{},{
SetShow:function(Skin)
	{
	(Skin||fastCSharp.PageView).OnSet.Add(fastCSharp.ThisFunction(this,this.Show));
	this.Show();
	},
Show:function()
	{
	for(var Values=[],Elements=fastCSharp.$('@lang=latex').GetElements(),Index=0;Index-Elements.length;++Index)
		{
		if(!fastCSharp.$ElementName(Elements[Index],'htmleditor'))
			{
			var Nodes=Elements[Index].childNodes;
			if(Nodes.length&&Nodes[0].tagName&&Nodes[0].tagName.toLowerCase()=='span')
				{
				if(window.MathJax)
					{
					var Text=fastCSharp.$Text(Nodes[0]);
					if(Text){
						Elements[Index].innerHTML=this.Format(Text);
						Values.push(Elements[Index]);
						}
					}
				else	{
					this.Load(fastCSharp.ThisFunction(this,this.Show));
					return;
					}
				}
			}
		}
	if(Values.length)	MathJax.Hub.Queue(['Typeset',MathJax.Hub,Values,{}]);
	},
Format:function(Text)
	{
	return '$\n'+Text.replace(/\xA0/g,' ').ToHTML()+'\n$';
	},
LoadConfig:function()
	{
	MathJax.Hub.Config({extensions:['tex2jax.js'],jax:['input/TeX','output/HTML-CSS'],elements:[''],tex2jax:{inlineMath:[['$','$'],['\\(','\\)']]}});
	},
Load:function(OnLoad)
	{
	if(!this.IsLoad)
		{
		this.IsLoad=1;
		var config=document.createElement('script');
		config.type='text/x-mathjax-config';
		config.text='fastCSharp.MathJax.LoadConfig();';
		document.getElementsByTagName('head')[0].appendChild(config);
		}
	fastCSharp.OnModule(['mathJax.MathJax'],OnLoad,1,1);
	},
ShowElement:function(Element)
	{
	MathJax.Hub.Queue(['Typeset',MathJax.Hub,Element]);
	},
TryShow:function(Element,Text)
	{
	if(Text){
		Element.innerHTML=this.Format(Text);
		if(window.MathJax)	MathJax.Hub.Queue(['Typeset',MathJax.Hub,Element]);
		else	this.Load(fastCSharp.ThisFunction(this,this.ShowElement,[Element]));
		}
	else	Element.innerHTML='';
	}
		});
fastCSharp.OnLoad(fastCSharp.MathJax.SetShow,fastCSharp.MathJax);